package net.zdsoft.wpchat.android.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sf.json.JSONObject;
import net.zdsoft.keel.action.ActionContext;
import net.zdsoft.keel.action.ActionSupport;
import net.zdsoft.wpchat.support.client.MemoryUser;

/**
 * 所有Action的基类
 * 
 * @author xuan
 * @version $Revision: 1.0 $, $Date: 2014-7-4 下午1:28:01 $
 */
public class BasicAction extends ActionSupport {
    private static final long serialVersionUID = 2240238791252877818L;
    protected Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 获取已经登录的用户信息。
     * 
     * @return 用户信息
     */
    protected MemoryUser getMemoryUser() {
        return (MemoryUser) ActionContext.getRequest().getSession().getAttribute(MemoryUser.KEY);
    }

    /**
     * 获取运营平台当前登录的用户信息.
     */
    public MemoryUser getSupportMemoryUser() {
        MemoryUser memoryUser = (MemoryUser) ActionContext.getSession().getAttribute(MemoryUser.KEY);
        ActionContext.getSession().setAttribute(MemoryUser.KEY, memoryUser);
        return memoryUser;
    }

    public String getMessage(String message) {
        JSONObject ret = new JSONObject();
        ret.put("type", "1");
        ret.put("message", message);
        return ret.toString();
    }

    public String getError(String error) {
        JSONObject ret = new JSONObject();
        ret.put("type", "2");
        ret.put("message", error);
        return ret.toString();
    }

}
